	Program parseVorticity

		implicit none
		complex, parameter :: Iunit = (0, 1)
		complex, allocatable, dimension (:,:) :: wk
		real, allocatable, dimension (:,:) :: k2
		real, allocatable, dimension (:) :: kx
		real, allocatable, dimension (:) :: ky
		real :: raux, iaux
		integer :: nx, ny, i, j
		real :: omega
		real :: enstrophy, energy, palinstrophy, wk2
		real :: time0
		namelist /inputs/nx,ny,omega

		open(16, file='parameters.lbm')
		read(16, inputs)
		close(16)

		allocate(wk(nx/2 + 1,ny))
		allocate(kx(nx/2+1))
		allocate(ky(ny))
		allocate(k2(nx/2 + 1,ny))

		!====================================================================
		!-------------------------------------------------------
		!     kx = 0,1,2,...,nx/2  distributed on proc
		!     ky = 0,1,2,...,ny/2,-(ny/2-1),...,-2,-1
		!     k2 = kx*kx + ky*ky
		!
		!     Adjusted so that largest magn ky is POSITIVE
		!-------------------------------------------------------
		do i = 1, nx/2+1
			kx (i) =  float(i-1)
		end do

		do j = 1, ny
			ky (j) =  float( MOD(j-1+ny/2,ny) - ny/2)
		end do
		ky (ny/2+1) =  float(ny/2)                       !.. Make ky_max > 0

		do j = 1, ny
			do i = 1, nx/2+1
				k2 (i,j) = kx(i)*kx(i) + ky(j)*ky(j)
			end do
		end do
		!====================================================================

		palinstrophy = 0.0
		enstrophy = 0.0
		energy = 0.0
		open(17, file='kvorticity.lbm')
		do j=1,ny
			do i=1,nx/2+1
				read(17, *) raux,iaux
! 				if ((j.gt.1).or.(i.gt.1)) then
				if ( j.gt.1 .or. (i.gt.1 .and. i.le.nx/2) ) then
					wk(i,j) = raux + Iunit*iaux
					wk2 = raux*raux + iaux*iaux
					energy = energy + wk2/k2(i,j)
					enstrophy = enstrophy + wk2
					palinstrophy = palinstrophy + k2(i,j)*wk2
				endif
			end do
		end do
		close(17)

		print*, 'energy = ', energy
		print*, 'enstrophy = ', enstrophy
		print*, 'palinstrophy = ', palinstrophy
		!aca falta pasar la vorticidad a unidades fisicas
		!también falta chequear que estamos escribiendo wk en el mismo orden (i,j) que los otros dos programas

		time0 = 0.0
		open(18, file='wk_0000', form='unformatted')
		write(18) time0, wk
		close(18)

	end Program

